package com.dg.cuckoo.admin.action.basicInformation;

import com.dg.cuckoo.admin.dto.basicInformation.constructionUnit.ConstructionUnitDto;
import com.dg.cuckoo.admin.service.ConstructionService;
import com.dg.cuckoo.admin.service.ProjectInfoServer;
import com.dg.cuckoo.core.BaseController;
import com.dg.cuckoo.core.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 基本资料-建设单位
 */
@RestController
@RequestMapping("/basicInformation/constructionUnit")
public class ConstructionUnit extends BaseController {

    @Autowired
    private ConstructionService service;
    @Autowired
    private ProjectInfoServer projectInfoServer;

    /**
     * 保存
     * @return
     */
    @PostMapping("save")
    public JsonResult<Void> save(ConstructionUnitDto dto){
        service.save(dto);
        return new JsonResult<>(OK);
    }

    /**
     * 修改
     */
    @PostMapping("update/{id}")
    public JsonResult<Void> update(ConstructionUnitDto dto,@PathVariable String id){
        service.update(dto,id);
        return new JsonResult<>(OK);
    }

    /**
     * 删除
     */
    @PostMapping("delect/{id}")
    public JsonResult<Void> delect(@PathVariable String id){
        service.delect(id);
        return new JsonResult<>(OK);
    }

    /**
     * 点击查询建设单位信息
     * @return
     */
    @PostMapping("openInfo/{id}")
    public JsonResult<ConstructionUnitDto> openInfo(@PathVariable String id){
        ConstructionUnitDto info = service.openInfo(id);
        return new JsonResult<>(OK,info);
    }

    /**
     * 建设单位页面信息
     */
    @PostMapping("clickUnitInfo")
    public JsonResult<String> clickUnitInfo(){
        String data = projectInfoServer.clickUnitInfo();
        return new JsonResult<>(OK,data);
    }
//
//    /**
//     * 建设单位点击显示二级标签
//     */
//    @PostMapping("clickUnitTreeInfo")
//    public JsonResult<String> clickUnitTreeInfo(String unit){
//        String data = projectInfoServer.clickUnitTreeInfo(unit);
//        return new JsonResult<>(OK,data);
//    }

    /**
     * 点击单位类型显示下拉选
     */
    @PostMapping("OpenDropDown")
    public JsonResult<List<String>> openDropDown(){
        List<String> data = service.openDropDown();
        return new JsonResult<>(OK,data);
    }

}
